// townscript for town 22: Machinery level

begintownscript;

variables;

int i,j,choice;

body;

beginstate INIT_STATE;	

if (get_flag(20,8) == 1) {
		set_terrain(57,39,137);
		set_terrain(58,39,137);
		}

if (get_flag(20,11) == 1) {
		set_terrain(30,33,137);
		set_terrain(29,33,137);
		}

if (get_flag(20,14) == 1) {
		set_terrain(13,33,137);
		set_terrain(12,33,137);
		}
if (get_flag(22,6) == 1)
		set_terrain(40,14,384);

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	move_to_new_town(20,7,53);
break;

beginstate 11;
if (get_flag(22,0) == 1)
		end();
	message_dialog("This is an old storeroom where broken machinery is dumped. Nobody has been here for quite some time. The silence is terrifying. You hope you can get away from this place quickly.","");
	set_flag(22,0,1);
break;

beginstate 12;
if (get_flag(5,17) == 2)
		end();
	if (get_flag(5,17) == 1)
			set_state_continue(38);
		message_dialog("This huge iron portcullis keeps unwanted visitors away from this part of the power level. Trying to break the portcullis would be a hell of a job, bashing stands as many chance as breaking.","Eventually you give up. There must be a quicker way inside.");
break;

beginstate 13;
if (get_flag(22,1) == 1)
		end();
	message_dialog("Whoever slept here, it was a very important person. A wooden floor, decorated with small flowers alongside the walls, covers the entire floor. You wonder who slept here.","");
	set_flag(22,1,1);
break;

beginstate 14;
if (get_flag(20,8) == 0)
		end();
	if (get_flag(22,2) == 1)
			end();
		message_dialog("So this is what the explosion was about. A huge piece of wall was blasted away by the pressure of the yellow cleaning stuff that couldn't stream through the pipe here, because you closed the valve.","You can now proceed to see what's on the other side of the wall.");
		set_flag(22,2,1);
break;

beginstate 15;
if (get_flag(20,11) == 0)
		end();
	if (get_flag(22,3) == 1)
			end();
		message_dialog("So this is what the explosion was about. A huge piece of wall was blasted away by the pressure of the yellow cleaning stuff that couldn't stream through the pipe here, because you closed the valve.","You can now proceed to see what's on the other side of the wall.");
		set_flag(22,3,1);
break;

beginstate 16;
if (get_flag(20,14) == 0)
		end();
	if (get_flag(22,4) == 1)
			end();
		message_dialog("So this is what the explosion was about. A huge piece of wall was blasted away by the pressure of the yellow cleaning stuff that couldn't stream through the pipe here, because you closed the valve.","You can now proceed to see what's on the other side of the wall.");
		set_flag(22,4,1);
break;

beginstate 17;
if (get_flag(22,5) == 1)
		end();
	message_dialog("You walk alongside this bookshelf and notice a piece of paper. You take it out and look at it. It looks like some sort of manual.","");
	change_spec_item(7,1);
	set_flag(22,5,1);
break;

beginstate 18;
if (get_flag(22,10) == 1) {
		message_dialog("The control panel has exploded, thanks to the reactor blowing up. The panel is useless now.","");
		end();
		}

if (get_flag(22,5) == 0) {
		message_dialog("The control panel lights are flickering all the time. You get dazed by these nice colors. You could start pressing buttons, but you wouldn't know what the heck to do, so you leave them alone.","You should try to look for some sort of manual or something, because without one, understanding this machine will be a hell of a job.");
		end();
		}
	reset_dialog();
	add_dialog_str(0,"You stand in front of a control panel, but some buttons here look familiar. You take out the manual you found in the small library. Its indeed a manual. A manual of this control panel.",0);
	add_dialog_str(1,"Finally you understand which buttons to press and which you'd better not press, for your own safety. Which buttons would you like to press?",0);
	add_dialog_choice(0,"None");
	add_dialog_choice(1,"ON button");
	add_dialog_choice(2,"OFF button");
	choice = run_dialog(1);
	
	if (choice == 1) {
			message_dialog("You decide you'd better still not press the buttons. You go away.","");
			end();
			}
	
	if (choice == 2) {
			reset_dialog();
			add_dialog_str(0,"You press the ON button. The machines to the right of you are starting to hum. You activated something, that's for sure. However, on the small display on the panel, a small text is displayed:",0);
			add_dialog_str(1,"_Please press a program choice_",0);
			add_dialog_choice(0,"33%");
			add_dialog_choice(1,"66%");
			add_dialog_choice(2,"Full power");
			choice = run_dialog(1);
			
		if (choice == 1) {
				message_dialog("Another text is displayed on the screen: _Program confirmed (33%). Please pull lever_","You pull the lever.");
				flip_terrain(32,22);
				message_dialog("You hear a zap to your right. The power is activated.","");
				set_terrain(40,14,384);
				set_flag(22,6,1);
				end();
				}
		
		if (choice == 2) {
				message_dialog("Another text is displayed on the screen: _Program confirmed (66%). Please pull lever_","You pull the lever.");
				flip_terrain(32,22);
				message_dialog("You hear a zap to your right. The power is activated.","");
				set_terrain(40,14,384);
				set_flag(22,6,1);
				end();
				}
		
		if (choice == 3) {
				reset_dialog();
				add_dialog_str(0,"A new text, in red letters, is displayed on the screen:",0);
				add_dialog_str(1,"_This is program _FULL POWER._ With this program, a person must be in the cooling room at all times to ensure the cooling of the power reactor. Can this be confirmed?_",0);
				add_dialog_choice(0,"Yes");
				add_dialog_choice(1,"No");
				choice = run_dialog(0);
				
				if (choice == 1) {
						message_dialog("The letters turn green, saying you can now pull the lever to your left. You pull it.","");
						flip_terrain(32,22);
						message_dialog("You hear a zap to your right. The power is activated.","");
						set_terrain(40,14,384);
						set_flag(22,6,1);
						set_flag(22,7,1);
						end();
						}
				
				if (choice == 2) {
						message_dialog("The red letters disappear and new ones take their place:","_In that case the program is not confirmed. Don't pull the lever. Go away or try again._");
						end();
						}
				}
		}
	
	if (choice == 3) {
			if (get_flag(22,6) == 0) {
					message_dialog("The power is already on OFF, so pushing this button is of no use.","");
					end();
					}
				message_dialog("You press the OFF button. Slowly by slowly, everything gets silent again. The power has been de-activated.","");
				set_flag(22,6,0);
				set_terrain(40,14,388);
				end();
				}
break;

beginstate 19;
	message_dialog("You try to pull the lever, but it doesn't work. When you look at the lever, a small sign says: _Before pulling the lever, choose a program on the control panel._","");
break;

beginstate 20;
if (get_flag(22,10) == 1) {
		message_dialog("The control panel has exploded, thanks to the reactor blowing up. The panel is useless now.","");
		end();
		}

if (get_flag(22,5) == 0) {
		message_dialog("The control panel lights are flickering all the time. You get dazed by these nice colours. You could start pressing buttons, but you wouldn't know what the heck to do, so you leave them alone.","");
		end();
		}
	if (get_flag(22,6) == 0) {
			message_dialog("Even now that you understand how the panel works thanks to the manual you found, the panel still does nothing more than it previously did. It has probably something to do with that other panel you saw.","Eventually you go away. You should probably first go to that other control panel you saw in the room with all the windows.");
			end();
			}
		if (get_flag(22,7) == 0) {
				message_dialog("You know how the thing works, you turned the power on, so what's wrong? Still the thing doesn't do anything. However, a small message is displayed on the panel:","_Cooling system should only be manually controlled when on FULL POWER mode._");
				end();
				}
			reset_dialog();
			add_dialog_str(0,"Finally! The control panel can now be accessed by you. There are several choices here you can make.",0);
			add_dialog_choice(0,"ON");
			add_dialog_choice(1,"OFF");
			add_dialog_choice(2,"Choose mode");
			choice = run_dialog(1);
			
			if (choice == 1) {
					if (get_flag(22,8) == 0) {
							message_dialog("The cooling is already on. Pressing this button is useless.","");
							set_state_continue(20);
							}
						message_dialog("You turned the cooling on. You can feel it. Its not as hot anymore as it used to be.","");
						set_flag(22,8,0);
						end();
					}
			
			if (choice == 2) {
					if (get_flag(22,8) == 1) {
							message_dialog("The cooling is already off. Pressing the button again will only result in you making the button more dirty with your dirty hands.","");
							set_state_continue(20);
							}
						message_dialog("You turn the cooling off, not knowing what might happen with the reactor. After a while, you discover what happens. Its not very pretty.","");
						
						// Cutscene explosion reactor.
						
						force_view_center(56,25);
						force_instant_terrain_redraw();
						pause(10);
						
						set_terrain(56,25,388);
						force_instant_terrain_redraw();
						pause(3);
						
						set_terrain(56,25,384);
						put_jagged_zap(56,25,53,13,0);
						put_jagged_zap(56,25,46,27,0);
						put_jagged_zap(56,25,58,41,0);
						run_animation_sound(169);
						force_instant_terrain_redraw();
						pause(7);
						
						set_terrain(56,25,388);
						force_instant_terrain_redraw();
						pause(5);
						
						set_terrain(56,25,384);
						force_instant_terrain_redraw();
						pause(3);
						
						set_terrain(56,25,388);
						put_jagged_zap(56,25,50,13,0);
						put_jagged_zap(56,25,46,22,0);
						put_jagged_zap(56,25,53,41,0);
						run_animation_sound(169);
						force_instant_terrain_redraw();
						pause(4);
						
						set_terrain(56,25,384);
						force_view_center(54,25);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(58,25);
						put_jagged_zap(56,25,59,13,0);
						put_jagged_zap(56,25,39,30,0);
						put_jagged_zap(56,25,61,41,0);
						run_animation_sound(169);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(54,25);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(57,25);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(52,25);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(59,25);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(54,25);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(57,25);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(52,25);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(59,25);
						force_instant_terrain_redraw();
						pause(2);
						
						force_view_center(56,25);
						put_boom_on_space(56,25,1,0);
						run_animation_sound(54);
						run_animation_sound(169);
						run_animation();
						set_terrain(56,25,385);
						force_instant_terrain_redraw();
						pause(10);
						
						set_terrain(40,14,388);
						force_view_center(56,30);
						force_instant_terrain_redraw();
						pause(10);
						
						message_dialog("You stare at the remains of the reactor. That was a huge explosion. The whole province must have heard it. It is not surprising that you hear footsteps coming down the stairs. You must get away quickly, before they see you.","It would be a good thing to tell Mayor Ruth of Voughton about what you did.");
						activate_hidden_group(5);
						set_flag(22,9,1);
						set_flag(22,10,1);
						}
				
				if (choice == 3) {
						message_dialog("You push the last button, only to get a message saying this option temporarily doesn't work.","");
						set_state_continue(20);
						}
break;

beginstate 21;
	message_dialog("This panel was destroyed. Probably to keep adventurers like you from destroying the reactor.","");
break;

beginstate 22;
	message_dialog("You have no idea what this lever does. You decide you'll leave it alone, just for the sake of it.","");
break;

beginstate 23;
if (get_flag(22,11) == 1)
		end();
	message_dialog("You stand at the gates to the reactor exhaust. Smoke comes from the extremely hot stones down the floor. The heat is tremendous. You'd better get out of this place, before you faint or something.","");
	set_flag(22,11,1);
break;

beginstate 24;
	message_dialog("The heat is enormous. You shouldn't get in there with at least proper protection. But as there is no protection of some sort in this room you can put on, you'd better stay out of the exhaust.","");
	block_entry(1);
break;

beginstate 25;
if (get_flag(22,10) == 1) {
		message_dialog("The control panel has exploded, thanks to the reactor blowing up. The panel is useless now.","");
		end();
		}
if (get_flag(22,6) == 0) {
		message_dialog("The panel is old and rusty. It probably doesn't function anymore. That's a pity, because you could have blown up the whole Creation halls with the stuff in the room in front of you.","However, the panel isn't in such a bad state that it really couldn't be used anymore. Maybe, if you could turn the power on somewhere, it would work again.");
		end();
		}
	message_dialog("Now that the power is on, you sit at the control panel and try to figure out what you have to do. However, quite soon you are asked about a password. You don't know it.","");
break;

beginstate 26;
	message_dialog("You can't use this panel anymore. Its totally broken. Even you can see that: a nice black hole decorates the panel.","");
break;

beginstate 27;
	message_dialog("You play a bit with this lever. It doesn't do anything anymore. It even doesn't say _clunk,_ It really is broken.","Dishearted, you move away.");
break;

beginstate 28;
	message_dialog("You managed to open the nuclear waste disposal room doors. You wish you hadn't. As soon as you try to come in, you get sick. You quickly step back, but its to late already.","");
	block_entry(1);
	set_party_status(7,75,1);
	set_party_status(0,25,1);
	set_party_status(12,10,1);
break;

beginstate 29;
if (get_flag(22,12) == 1)
		set_state_continue(30);
	message_dialog("The air here is really bad. You start to feel ill after standing in the corridor for a while. Better walk on.","");
	set_flag(22,12,1);
break;

beginstate 30;	
if (get_flag(22,13) == 1) 
		end();
	message_dialog("The air here smells less bad, and you slowly feel better. You wonder what causes the air to be so polluted.","");
	set_flag(22,13,1);
break;
	
beginstate 31;
if (get_flag(22,14) == 1)
		set_state_continue(32);
	run_animation_sound(3);
	message_dialog("The air here is very polluted. Its so bad, that you start to feel really ill. You shouldn't stand here to long.","");
	set_party_status(7,75,1);
	set_flag(22,14,1);
break;

beginstate 32;	
if (get_flag(22,15) == 1) 
		end();
	message_dialog("The air here smells less bad, but you still stay ill. It has probably something to do with something behind these shut doors you passed. You wonder though, why the air is so bad.","");
	set_flag(22,15,1);
break;

beginstate 33;
if (get_flag(22,16) == 1)
		end();
	message_dialog("This is the room where the air was purified before it went into the building. You see why the air was so bad in that part of the hallway you walked. The pipe that carried the polluted air out was damaged.","");
	set_flag(22,16,1);
break;

beginstate 34;
	message_dialog("This passage was sealed off for some reason. You can't get to the machines behind it this way.","");
	block_entry(1);
break;